import { search1 } from '@/services/api/article';
import { convertPageData } from '@/utils/request';
import { ActionType, PageContainer, ProColumns, ProTable, ProFormTextArea } from '@ant-design/pro-components';
import { useRef, useState } from 'react';



export default () => {
  const refAction = useRef<ActionType>(null);
  const [selectedRowKeys, selectRow] = useState<number[]>([]);
  const [visible, setVisible] = useState(false);
  const [searchIndex, setSearchIndex] = useState<API.LuceneResultBookVO>();
  const [article, setArticle] = useState<API.LuceneResultBookVO>();
  const columns: ProColumns<API.LuceneResultBookVO>[] = [
    {
      title: '文章ID',
      dataIndex: 'articleId',
      width: 50,
      search: false,
    },
    {
      title: '文章标题',
      dataIndex: 'title',
      width: 50,
      search: false,
    },
    {
      title: '作者',
      dataIndex: 'author',
      width: 50,
      search: false,
    },
    {
      title: '文章内容',
      dataIndex: 'content',
      width: 100,
      render: (_: any, record) => {
        const text = record?.highlights?.join('...') || '';
        return <div dangerouslySetInnerHTML={{ __html: text }}></div>

      }
    },
    {
      title: '发布日期',
      dataIndex: 'publishTime',
      width: 50,
      search: false,
    },
    {
      title: '得分',
      dataIndex: 'score',
      width: 50,
      search: false,
    }
  ];


  return (
    <PageContainer>
      <ProTable<API.LuceneResultBookVO>
        actionRef={refAction}
        rowKey="articleID"
        manualRequest = {true}
        request={async (params = {}) => {
          return convertPageData(await search1(params));
        }}
        columns={columns}
        rowSelection={{
          onChange: (rowKeys) => {
            selectRow(rowKeys as number[]);
          },
        }}
      />
    </PageContainer>


  );
};
